local Button = {}
local pointer = love.mouse.getSystemCursor("hand")

function Button:new(x, y, icon, fn)
	local b = {}
	b.icon = icon
	b.fn = fn
	b.x = x - 16
	b.y = y - 16

	setmetatable(b, self)
	self.__index = self
	return b
end

function Button:update(dt, mx, my)
	if
		mx > self.x
		and mx < self.x + self.icon:getWidth() * scaleMin * 0.3
		and my > self.y
		and my < self.y + self.icon:getHeight() * scaleMin * 0.3
	then
		love.mouse.setCursor(pointer)
		return true
	end
	return false
end

function Button:checkClick(mx, my)
	if
		mx > self.x
		and mx < self.x + self.icon:getWidth() * scaleMin * 0.3
		and my > self.y
		and my < self.y + self.icon:getHeight() * scaleMin * 0.3
	then
		return true
	end
end

function Button:draw()
	local iconOffset = 2 * scaleMin
	lg.setShader(overlayShader)
	for x = -1, 1 do
		for y = -1, 1 do
			lg.draw(self.icon, self.x + x * iconOffset, self.y + y * iconOffset, 0, 0.3 * scaleMin)
		end
	end
	lg.setShader()
	lg.draw(self.icon, self.x, self.y, 0, scaleMin * 0.3)
end

return Button
